#include <iostream>
#include <boost/asio.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "session.h"
#include <map>

//异步echo服务器
/*
使用智能指针改进double free问题
*/
class Server {
public:
    Server(boost::asio::io_context& ioc, short port);
    void ClearSession(std::string uuid);
    ~Server(){std::cout << "Server destructor." <<std::endl;};
private:
    void StartAccept();
    void HandleAccept(std::shared_ptr<Session> new_session, const boost::system::error_code& error);
    
    boost::asio::io_context &_ioc;
    boost::asio::ip::tcp::acceptor _acceptor;

    /*使用关联容器存储session,方便重连、踢人等操作*/
    std::map<std::string,std::shared_ptr<Session>>sessions_;
};

